<?php
/**
 * Role
 * @filesource
 */
/**
 * Namespace
 */
namespace framework\library\access_control;
/**
 * Dependencies
 */
use framework\library\authentication\Auth;
/**
 * Role Class
 *
 * Authentication and Authorization for Plurious
 *
 * @author Randy Casburn <randy@plurious.com>
 * @copyright Copyright Plurious Software, all rights reserved
 * @license MIT
 * @license http://www.opensource.org/licenses/mit-license.html
 * @link http://plurious.com/framework/documentation/classes/Front.html
 * @version 2.1
 * 
 * @uses framework\Front
 */
class Role {

    /**
     * Specifically used to check if a user has a specific role
     * 
     * GIVEN: role names of member, editor, customer, admin
     * USE: $user->isMember(); $user->isEditor(); $user->isCustomer(); $user->isAdmin();
     * 
     * The magic method is used since we cannot determine the names of the
     * roles that may exist in the system.  So this method overloads those
     * possible names.
     * 
     * @param string $name
     * @return boolean To indicate whether a role is associated with this user
     */
    public function __call($name, $arguments) {
        $context = $this->config->get('context');
        if (isset($this->roles[$context])) {
            $roles = $this->roles[$context];
        }
        foreach ($roles as $role) {
            $method = 'is' . strtolower($role);
            if (strtolower($name) == $method) {
                return true;
            }
        }
        return false;
    }
}

?>
